<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>区域论坛系统</title>
    <link rel="stylesheet" href="/css/layui.css">
    <link rel="stylesheet" href="/css/index.css">
    <script src="/layui.js"></script>
    <style>
        h1{
            text-align: center;
            margin: 20px 0 40px 0;
            font-weight: 700;
        }
        #loginRoot{
            width: 500px;
            height: 300px;
            margin: 180px auto;
        }
    </style>
</head>
<body>
    <header>
        <div class="logo">
            区域论坛系统
        </div>
        <ul>
            <li><a href="/">论坛首页</a></li>
            <li><a href="/article/addArticle">发帖</a></li>
            <li><a href="/article/about">关于我们</a></li>

        </ul>
       <div class="user">
        <div class="login">
          <a href="/user/userLogin">登录</a>
      </div>
      <div class="regrister">
          <a href="/user/regrister">注册</a>
      </div>
       </div>
    </header>
    <div id="loginRoot">
        <h1>用户登录</h1>
        <div class="root">
            <form class="layui-form" action="">
            
                <div class="layui-form-item">
                  <label class="layui-form-label">用户名</label>
                  <div class="layui-input-block">
                    <input type="text" name="username" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">密码</label>
                  <div class="layui-input-block">
                    <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                  </div>
    
               <br>
                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即登录</button>
                  </div>
                </div>
              </form>
              <script>
                //Demo
                layui.use( function(){
                  var form = layui.form;
                  var $ = layui.$
                  //监听提交
                  form.on('submit(formDemo)', function(data){
                    $.post({
                        url:"/user/doUserLogin",
                        data:data.field,
                        success:function(res){
                            if(res.code == 0){
                                sessionStorage.user = JSON.stringify(res.info)
                                window.location.href = "/"
                            }else{
                                layer.msg(res.msg);
                            }
                        }
                    })
                   
                    return false;
                  });
                });
                </script>
        </div>
    </div>
</body>
</html>